<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>生成器函数参数</title>
</head>

<body>
    <script>
        function* gen(arg) {
            console.log(arg)        // AAA
            let one = yield 111     // {value: 111, done: false}
            console.log(one)        // BBB
            let two = yield 222     // {value: 222, done: false}
            console.log(two)        // CCC
            let three = yield 333   // {value: 333, done: false}
            console.log(three)      // DDD
            // {value: undefined, done: true}
        }

        //执行获取迭代器对象
        let iterator = gen('AAA')
        console.log(iterator.next())        // 会执行yield 111;
        //next方法可以传入实参
        console.log(iterator.next('BBB'))   // 会执行yield 222;
        console.log(iterator.next('CCC'))   // 会执行yield 333;
        console.log(iterator.next('DDD'))   // 继续往后走，未定义;
    </script>
</body>

</html>